package zz_loesninger;

import eks.simpla.*;
import org.simpla.SimplaView;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import java.util.Date;
import org.simpla.R;
import org.simpla.SimplaActivity;

/**
 * 
 * @author Jacob Nordfalk
 */
public class AnalogtUr extends SimplaActivity {


  int x = 0;
  int y = 0;
  int xMinutes = 0;
  int yMinutes = 0;
  int xHours = 0;
  int yHours = 0;
  int r = 0;
  int xc = 0;
  int yc = 0;
  
  public class MinGrafik extends SimplaView {

    @Override
    protected void onDraw(Canvas canvas) {

        

        xc = this.getWidth()/2;
        yc = this.getHeight()/2;
        r = xc;

       RectF view = new RectF(0, (this.getHeight()-this.getWidth())/2, this.getWidth(), this.getHeight()-(this.getHeight()-this.getWidth())/2);
       Path cirkel = new Path();
       Path linie = new Path();

       cirkel.addArc(view, 0, 360);
      // cirkel.addCircle(150, 150, 100, Direction.CW);
     //  x = r*Math.sin(2*Math.PI*s/60);
     //  y = r*Math.cos(2*Math.PI*s/60);
       Paint tekstStregtype = new Paint();
       tekstStregtype.setColor(Color.WHITE);
       tekstStregtype.setAntiAlias(true);
    //   tekstStregtype.setTextSize(24);
      canvas.drawPath(cirkel, tekstStregtype);
      tekstStregtype.setColor(Color.RED);
      canvas.drawLine(xc, yc, x, y, tekstStregtype);
      tekstStregtype.setColor(Color.RED);
      for (int i = 0; i<60; i++){
        if((i+45) % 5 == 0){
       int y = yc + (int) (r * Math.sin(2 * Math.PI * (i+45) / 60));
       int x = xc + (int) (r * Math.cos(2 * Math.PI * (i+45) / 60));
       int ys = yc + (int) (0.8*r * Math.sin(2 * Math.PI * (i+45) / 60));
       int xs = xc + (int) (0.8*r * Math.cos(2 * Math.PI * (i+45) / 60));
      canvas.drawLine(xs, ys, x, y, tekstStregtype);}
        else
          {
       int y = yc + (int) (r * Math.sin(2 * Math.PI * (i+45) / 60));
       int x = xc + (int) (r * Math.cos(2 * Math.PI * (i+45) / 60));
       int ys = yc + (int) (0.9*r * Math.sin(2 * Math.PI * (i+45) / 60));
       int xs = xc + (int) (0.9*r * Math.cos(2 * Math.PI * (i+45) / 60));
      canvas.drawLine(xs, ys, x, y, tekstStregtype);}
      }
      tekstStregtype.setColor(Color.BLACK);
      canvas.drawLine(xc, yc, xMinutes, yMinutes, tekstStregtype);
      canvas.drawLine(xc, yc, xHours, yHours, tekstStregtype);
     //  canvas.rotate(x*.15f);
     //  canvas.drawText(navnet, x, 20+y, tekstStregtype);

    }
  }

	public void simplaMain() {

    // Indlæs res/drawable/car.png
 //   enBil = getResources().getDrawable(R.drawable.car);
    Date dato = new Date();
    int s = dato.getSeconds();
    // Opret grafik-view
    MinGrafik minGrafik = new MinGrafik();
    minGrafik.setBackgroundColor(Color.DKGRAY);
		simpla.setContentView(minGrafik);

    simpla.sleep(500); // vent 0.5 sekund

  //  navnet = simpla.showEditTextDialog("Hvad hedder du?", "(skriv dit navn her)");

    int n=0;
    while (n<100) {
      dato = new Date();
 
      s = dato.getSeconds()+45;
 
      y = yc + (int) (r * Math.sin(2 * Math.PI * s / 60));
      x = xc + (int) (r * Math.cos(2 * Math.PI * s / 60));
      s = dato.getMinutes()+45;
      yMinutes = yc + (int) (0.7*r * Math.sin(2 * Math.PI * s / 60));
      xMinutes = xc + (int) (0.7*r * Math.cos(2 * Math.PI * s / 60));
      s = dato.getHours();
      if (s>12) s -= 12;
      s+=9;
      //s=12+9;
      yHours = yc + (int) (r/2 * Math.sin(2 * Math.PI * s / 12));
      xHours = xc + (int) (r/2 * Math.cos(2 * Math.PI * s / 12));
    //  y = n*3;
      minGrafik.postInvalidate(); // Får Android til at kalde onDraw() på viewet
      simpla.sleep(1000); // vent 0.1 sekund
      n = n + 1;
    }

    //navnet = "SLUT!";
    minGrafik.postInvalidate(); // Lad Android gentegne viewet med den nye tekst
    simpla.sleep(1000);
    
	}
}
